CROSS_COMPILE=
CC=$(CROSS_COMPILE)gcc
AS=$(CROSS_COMPILE)as
OBJCOPY=$(CROSS_COMPILE)objcopy
LD=$(CROSS_COMPILE)ld

BUILD=build/
SRC=src/
OBJS = kvm_test test.bin
OBJS := $(addprefix $(BUILD), $(OBJS))

all: $(OBJS)
 
$(BUILD)%.bin: $(BUILD)%.elf
	$(OBJCOPY) -O binary $< $@

$(BUILD)test.elf: $(BUILD)test.o
	$(LD) -Ttext=0x80000 -o $@ $<

$(BUILD)test.o: $(SRC)test.S
	$(AS) -g -o $@ $<

 $(BUILD)kvm_test: $(SRC)kvm_test.c
	$(CC) -g -o $@ $< 
	
run: $(OBJS)
	@echo "Run kvm_test..."
	cd $(BUILD) && \
	./kvm_test
	@echo "Test completed."

clean:
	rm -f $(BUILD)*.o $(BUILD)*.elf $(BUILD)*.bin $(BUILD)kvm_test
